﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using UIShare;

using EFong.Contract;
using EFong.View.Proxy;

namespace EFong.View.Base
{
    public partial class Frm_Void : BasicForm
    {
        private string _orderRef;

        private Contract.FlightOrder _flightOrder = null;
        private Contract.TrainTicketOrder _trainTicketOrder = null;
        private Contract.HotelBooking _hotelBooking = null;
        private Contract.OtherBusiness _otherBusiness = null;
        private Contract.TouringParty _touringParty = null;

        private BusinessServiceProxy _businessServiceProxy;
        private MasterServiceProxy _masterServiceProxy;

        public Frm_Void(Contract.FlightOrder flightOrder) : this()
        {
            this._flightOrder = flightOrder;
            txt_OrderRef.SetText(flightOrder.Ref);
        }

        public Frm_Void(Contract.TrainTicketOrder trainTicketOrder)
            : this()
        {
            this._trainTicketOrder = trainTicketOrder;
            txt_OrderRef.SetText(trainTicketOrder.Ref);
        }

        public Frm_Void(Contract.HotelBooking hotelBooking)
            : this()
        {
            this._hotelBooking = hotelBooking;
            txt_OrderRef.SetText(hotelBooking.Ref);
        }

        public Frm_Void(Contract.OtherBusiness otherBusiness)
            : this()
        {
            this._otherBusiness = otherBusiness;
            txt_OrderRef.SetText(otherBusiness.Ref);
        }

        public Frm_Void(Contract.TouringParty touringParty)
            : this()
        {
            this._touringParty = touringParty;
            txt_OrderRef.SetText(touringParty.Ref);
        }

        public Frm_Void()
        {
            InitializeComponent();
        }

        protected override void InitFields()
        {
            this._businessServiceProxy = BusinessServiceProxy.GetInstance();
            this._masterServiceProxy = MasterServiceProxy.GetInstance();
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_Confirm_Click(object sender, EventArgs e)
        {
            if (_flightOrder != null)
            {
                if (_businessServiceProxy.VoidFlightOrder(_flightOrder, this.txt_VoidCause.GetText()).IsSuccess)
                {
                    DialogResult = DialogResult.OK;
                    MsgBox.Info(MsgResource.Void_Complete);
                    this.Close();
                    return;
                }
            }

            if (_trainTicketOrder != null)
            {
                if (_businessServiceProxy.VoidTrainTicketOrder(_trainTicketOrder, this.txt_VoidCause.GetText()).IsSuccess)
                {
                    DialogResult = DialogResult.OK;
                    MsgBox.Info(MsgResource.Void_Complete);
                    this.Close();
                    return;
                }
            }

            if (_hotelBooking != null)
            {
                if (_businessServiceProxy.VoidHotelBooking(_hotelBooking, this.txt_VoidCause.GetText()).IsSuccess)
                {
                    DialogResult = DialogResult.OK;
                    MsgBox.Info(MsgResource.Void_Complete);
                    this.Close();
                    return;
                }
            }

            if (_otherBusiness != null)
            {
                if (_businessServiceProxy.VoidOtherBusiness(_otherBusiness, this.txt_VoidCause.GetText()).IsSuccess)
                {
                    DialogResult = DialogResult.OK;
                    MsgBox.Info(MsgResource.Void_Complete);
                    this.Close();
                    return;
                }
            }

            if (_touringParty != null)
            {
                if (_masterServiceProxy.VoidTouringParty(_touringParty, this.txt_VoidCause.GetText()).IsSuccess)
                {
                    DialogResult = DialogResult.OK;
                    MsgBox.Info(MsgResource.Void_Complete);
                    this.Close();
                    return;
                }
            }
        }

    }
}
